//
//  SYS_AboutUsVC.m
//  System_App
//
//  Created by 伟徐 on 2017/11/28.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_AboutUsVC.h"
#import "DGHLoadWebView.h"

@interface SYS_AboutUsVC ()<UIWebViewDelegate>

@property (nonatomic,strong) DGHLoadWebView *loadWebViewLayer;
@end

@implementation SYS_AboutUsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBar];
    [self loadWebView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- setter and getter
- (void)setNavigationBar{
    self.title = @"关于我们";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"SYS_Public_back" highImage:nil title:nil target:self action:@selector(aboutUsVCBack)];
    self.view.backgroundColor = DSCOLOR_WHITE;
    
    _loadWebViewLayer = [[DGHLoadWebView alloc] init];
    _loadWebViewLayer.frame = CGRectMake(0, 42, SCREENWIDTH, 2);
    [self.navigationController.navigationBar.layer addSublayer:_loadWebViewLayer];
}

- (void)loadWebView{
    UICKeyChainStore *keychainStore = [UICKeyChainStore keyChainStore];
    NSString *pid = [keychainStore stringForKey:@"pid"];
    NSString *session = [SYS_LoginModel instance].sessionInfo.session;
    //创建webview，加载详情页
    UIWebView *webView=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT-NavBarHeight)];
    webView.delegate= self;
    webView.dataDetectorTypes = UIDataDetectorTypeNone;
    [self.view addSubview:webView];
    
    NSString *urlSrting=[NSString stringWithFormat:@"%@/adm/sysapp/about",SERVICE_IP];
    NSURL *url = [NSURL URLWithString:urlSrting];
    NSString *body = [NSString stringWithFormat: @"session=%@&pid=%@", session,pid];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
    [request setHTTPMethod: @"POST"];
    webView.scrollView.bounces=NO;
    [request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
    [webView loadRequest: request];
    
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView {

    [_loadWebViewLayer startLoad];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [_loadWebViewLayer finishedLoadWithError:nil];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
    [_loadWebViewLayer finishedLoadWithError:error];
    
}

- (void)dealloc {
    
    [_loadWebViewLayer closeTimer];
    [_loadWebViewLayer removeFromSuperlayer];
    _loadWebViewLayer = nil;
}
#pragma mark -- touch and event
- (void)aboutUsVCBack{
    [self.navigationController popViewControllerAnimated:YES];
    //_loadWebViewLayer = nil;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
